package q202_isHappy;

import java.util.HashSet;
import java.util.Set;

public class Solution_1 {
    public static void main(String[] args) {
        Solution_1 s = new Solution_1();
//        int a = 6, c =0;
//        for (int i = 0; i < 10; i++) {
//            while(a > 0){
//                int b = a % 10;
//                c += b * b;
//                a = a / 10;
//            }
//            System.out.println(c);
//            a = c;
//            c = 0;
//        }
        System.out.println(s.isHappy(2));
    }

    public boolean isHappy(int n) {
        int count = 0;
        Set<Integer> set = new HashSet<Integer>();
        while(n != 1){
            while(n > 0){
                int b = n % 10;
                count += b * b;
                n = n / 10;
            }
            boolean flag = set.add(count);
            if(!flag){
                return false;
            }
            n = count;
            count = 0;

        }
        return true;
    }
}
